<template>
	<view class="start-box">
		<view class="top-hed">绮径</view>
		<image src="/static/index_bg.png" class="bg" mode=""></image>
		<view class="handle" @click="wxLogin">
		    <!-- <image
		    style="width: 50rpx;height: 50rpx; margin-right: 10rpx;"
		    src="/static/icon-login12-weixin.png"></image> -->
			<text>去登陆</text>
		</view>
	</view>
</template>

<script>
	import { userWxLogin } from '@/api/user.js'
	export default {
		components:{
			
		},
		data() {
			return {
				def: {
					url: ''
				},
				back: ''
			}
		},
		onShow() {
			
		},
		onLoad(ops) {
			this.back = ops.back
			this.def.url = ops.obj
			let token = uni.getStorageSync('token') || ''
			if(!token){
				this.isShowModal = true
			}else{
				console.log('this.def.url',this.def.url)
				uni.reLaunch({
					// url: this.def.url ? '/' + this.def.url : '/pages/home/home'
					url: '/pages/home/home'
				})
			}
		},
		computed:{
			
		},
		methods: {
			wxLogin(){
				uni.showLoading({
					title: '登陆中...'
				})
				wx.login({
					success: wxRes => {
						console.log(wxRes,'------code-------------')
						let code = wxRes.code
						userWxLogin({code:code}).then((res) => {
							console.log('res',res)
							uni.setStorageSync('userInfo',res)
							uni.setStorageSync('token',res.token)
							uni.hideLoading()
							// uni.switchTab({
							// 	url: '/pages/home/home'
							// })
							console.log('this.def.url',this.def.url)
							if(this.back) {
								uni.reLaunch({
									url: this.back
								})
							}else{
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}).catch((err) => {
							uni.showToast({
								title: "登录失败！",
								icon: 'none'
							})
							uni.hideLoading()
						})
					},
					fail:function(resp){
						uni.hideLoading()
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	.start-box{
		overflow: hidden;
		background: linear-gradient(180deg, #E4919D 0%, rgba(216,216,216,0.00) 100%);
		height: 100vh;
		.top-hed {
		   width: 100%;
		  height: 200rpx;
		  text-align:center;
		  line-height: 200rpx; 
		   color: white;
		   font-weight:bold;
		   position: fixed;
		   top: 0;
		   left: 0;
		   z-index: 9;
		}
		.bg{
			width: 100%;
			height: 962rpx;
		}
		.handle {
		  background-color: #E4919D;
		  border-radius: 20rpx;
		  display: flex;
		  justify-content: center;
		  align-items: center;
		  color: #fff;
		  font-size: 35rpx;
		  margin: 0 65rpx;
		  margin-top: 100rpx;
		  padding: 20rpx 30rpx;
		  margin-bottom: 40rpx;
		}
	}
	.content {
		/* display: flex; */
		/* flex-direction: column; */
		/* align-items: center; */
		/* justify-content: center; */
	}
	/deep/ .neil-modal__content{
		padding: 60rpx 45rpx;
	}
	/deep/ .neil-modal__container{
		width: 640upx;
		padding-top: 35rpx;
	}
</style>
